package flc.ast.adapter;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;

import flc.ast.R;
import flc.ast.bean.PicAlbumBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;

public class PicAlbumAdapter extends StkProviderMultiAdapter<PicAlbumBean> {

    private boolean isEdit;

    public PicAlbumAdapter() {
        addItemProvider(new PicAlbumItemProvider());
    }

    public void setEdit(boolean edit) {
        isEdit = edit;
    }

    private class PicAlbumItemProvider extends BaseItemProvider<PicAlbumBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_pic_album;
        }

        @Override
        public void convert(@NotNull BaseViewHolder baseViewHolder, PicAlbumBean picAlbumBean) {
            baseViewHolder.setText(R.id.tvPicAlbumTime, picAlbumBean.getTime());

            if (picAlbumBean.isSelected()){
                baseViewHolder.setText(R.id.tvPicAlbumSel,getContext().getString(R.string.cancel_all_sel));
            }else {
                baseViewHolder.setText(R.id.tvPicAlbumSel,getContext().getString(R.string.all_sel));
            }

            baseViewHolder.setGone(R.id.tvPicAlbumSel, !isEdit);

            RecyclerView rvPicAlbumChild = baseViewHolder.getView(R.id.rvPicAlbumChild);
            rvPicAlbumChild.setLayoutManager(new GridLayoutManager(getContext(), 3));
            AlbumChildAdapter albumChildAdapter = new AlbumChildAdapter();
            rvPicAlbumChild.setAdapter(albumChildAdapter);
            albumChildAdapter.setEdit(isEdit);
            albumChildAdapter.setPicAlbumBean(picAlbumBean);
            albumChildAdapter.setList(picAlbumBean.getClassBeanList());
            albumChildAdapter.setOnItemClickListener(getOnItemClickListener());
            albumChildAdapter.setOnItemLongClickListener(getOnItemLongClickListener());
        }
    }
}
